<template>
  <div class='search'>
    <f-drawer ref='orderCalcuateDrawer' title='订单核算' ok-text='重新计算' width='75%' @submit='handleSubmit' @visibleChange='visibleChange'>
      <a-tabs @tabClick='tabClick' :defaultActiveKey='current' v-model='current' :animated='false'>
        <a-tab-pane tab='基础数据' key='form1' v-if='drawerVisible&&tag'>
          <hy-order-calculate-tab1 ref='form1' v-if="current=='form1'"></hy-order-calculate-tab1>
        </a-tab-pane>
        <a-tab-pane tab='部门结算政策' key='dept' v-if='drawerVisible&&tag && deptType=="ZY"'>
          <hy-order-calculate-dept ref='dept' v-if="current=='dept'"></hy-order-calculate-dept>
        </a-tab-pane>
        <a-tab-pane tab='渠道商结算政策' key='form2' v-if='drawerVisible && tag && formData.saleManId'>
          <hy-order-calculate-tab2 ref='form2' v-if="current=='form2'"></hy-order-calculate-tab2>
        </a-tab-pane>
        <a-tab-pane tab='商务经理结算政策' key='form3' v-if='drawerVisible && tag && formData.saleManIdD'>
          <hy-order-calculate-tab3 ref='form3' v-if="current=='form3'"></hy-order-calculate-tab3>
        </a-tab-pane>
        <a-tab-pane tab='片区服务商结算政策' key='form4' v-if='drawerVisible && tag && formData.saleManIdC'>
          <hy-order-calculate-tab4 ref='form4' v-if="current=='form4'"></hy-order-calculate-tab4>
        </a-tab-pane>
        <a-tab-pane tab='商务总负责人结算政策' key='form5' v-if='drawerVisible && tag && formData.saleManIdE'>
          <hy-order-calculate-tab5 ref='form5' v-if="current=='form5'"></hy-order-calculate-tab5>
        </a-tab-pane>
<!--        <a-tab-pane tab='强制更新' key='profit' v-if='drawerVisible && tag'>
          <hy-order-calculate-profit ref='profit' v-if="current=='profit'"></hy-order-calculate-profit>
        </a-tab-pane>-->
      </a-tabs>
    </f-drawer>
  </div>
</template>
<script>
import HyOrderCalculateTab1 from "./hy_order_calculate_tab1"
import HyOrderCalculateTab2 from "./hy_order_calculate_tab2"
import HyOrderCalculateTab3 from "./hy_order_calculate_tab3"
import HyOrderCalculateTab4 from "./hy_order_calculate_tab4"
import HyOrderCalculateTab5 from "./hy_order_calculate_tab5"
import HyOrderCalculateDept from "./hy_order_calculate_dept"
import HyOrderCalculateProfit from "./hy_order_calculate_profit"

export default {
  name: "HyOrderCalcuateDrawer",
  props: {},
  data() {
    return {
      refs: this.$refs,
      drawerVisible: false,
      isEdit: false,
      tag: true,
      deptType:null,
      title: "",
      current: "form1",
      formData: {},
      forms: [
        "form1",
        "form2",
        "form3",
        "form4",
        "form5"
      ]
    }
  },
  methods: {
    showDrawer(data, tag,deptType) {
      this.isEdit = false
      this.tag = tag
      this.deptType = deptType
      if (data && data.orderId) {
        this.isEdit = true
        this.formData = data
      } else {
        this.formData = {}
      }
      let form = "form1"
      this.refs["orderCalcuateDrawer"].show()
      this.tabClick(form)
    },
    handleSubmit(callback) {
      this.refs[this.current].handleSubmit(()=>{
        this.$refs.orderCalcuateDrawer.close();
        this.$emit("success")
      })
    },
    visibleChange(drawerVisible) {
      this.drawerVisible = drawerVisible
    },
    tabClick(name) {
      this.current = name
      this.$nextTick(() => {
        this.refs[this.current].setData(this.formData)
      })
    }
  },
  computed: {
    drawerTitle: function() {
      return this.title
    }
  },
  created() {
  },
  components: { HyOrderCalculateTab1, HyOrderCalculateTab2, HyOrderCalculateTab3, HyOrderCalculateTab4, HyOrderCalculateTab5, HyOrderCalculateDept,HyOrderCalculateProfit }
}
</script>

<style scoped lang='less' rel='stylesheet/less'>

</style>
